package com.coco.live.controller;

import com.coco.common.result.CommonResponse;
import com.coco.live.pojo.TbLive;
import com.coco.live.service.ILiveService;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @date 2021/07/27 18:51
 * @version 1.0
 */
@RestController
@RequestMapping("/live")
@CrossOrigin
public class LiveController {

    @Autowired
    private ILiveService liveService;


    /**
     * 创建直播
     * @param live
     * @param itmes
     * @return
     */
    @PostMapping("/addLive")
    public CommonResponse addLive(@RequestBody TbLive live, @RequestParam("itmes") Long[] itmes, @RequestParam("token") String token){
        return liveService.addLive(live,itmes,token);
    }

    /**
     * 直播列表（模糊）
     * @param tbLive
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/findPage")
    public PageInfo findPage(@RequestBody TbLive tbLive
            , @RequestParam(value = "page",defaultValue = "1")int page
            ,@RequestParam(value = "size",defaultValue = "20")int size){
        return liveService.findPage(tbLive,page,size);
    }

    /**
     * 修改直播状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/update")
    public CommonResponse update(@RequestParam("id")Long id,@RequestParam("status")String status){
        try{
            liveService.update(id,status);
            return new CommonResponse(0,"修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return new CommonResponse(-1,"修改失败");
        }
    }

    /**
     * 查询当前直播信息
     * @param id
     * @return
     */
    @GetMapping("/findOne")
    public TbLive findOne(Integer id){
        return liveService.findOne(id);
    }


}
